/**
 * 
 */
package com.zhiteng.utils.common;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.zhiteng.utils.tencent.campus.DecodeUtil;

/**  
* <p>Title: HttpClientUtil.java</p>  
* <p>Description: </p>  
* @author dragon  
* @date 2018年11月7日  
* @version 1.0  
*/
public class HttpClientUtil {
	//	发送get请求
	public static String get(String url) {
		CloseableHttpClient httpClient = HttpClients.createDefault();
		String jsonStr = "";
		try {
			HttpGet httpGet = new HttpGet(url);
			CloseableHttpResponse response = httpClient.execute(httpGet);
			try {
				//	获取响应实体
				HttpEntity entity = response.getEntity();
				if (entity != null) {
					String content = EntityUtils.toString(entity);
					jsonStr = DecodeUtil.decodeUnicode(content);
				}
			} finally {
				response.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				httpClient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return jsonStr;
	}
}
